﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Things.Common;
using LTP.Accounts.Bus;
namespace Things.ThingsWeb.GoodsOrders
{
    public partial class Modify : Page
    {
        protected Guid GoodsOrdersID
        {
            get
            {
                Guid goodsOrdersID = Guid.Empty;
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    goodsOrdersID = new Guid(Request.Params["id"]);
                }
                return goodsOrdersID;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    ShowInfo(GoodsOrdersID);
                }
            }
        }

        private void ShowInfo(Guid GoodsOrdersID)
        {
            Things.BLL.GoodsOrders bll = new Things.BLL.GoodsOrders();
            Things.Model.GoodsOrders model = bll.GetModel(GoodsOrdersID);
            if (model != null)
            {
                this.lblGoodsOrdersID.Text = model.GoodsOrdersID.ToString();
                this.txtBuyerAccount.Text = model.BuyerAccount;
                this.txtBuyerAddress.Text = model.BuyerAddress;
                this.txtTotalPrice.Text = model.TotalPrice.ToString();
                this.txtBuyDate.Text = model.BuyDate.ToString();
                this.txtSendDate.Text = model.SendDate.ToString();
                this.txtCancelDate.Text = model.CancelDate.ToString();
                this.txtStatus.Text = model.Status;
                this.chkIsCompleted.Checked = model.IsCompleted;
                this.txtModifiedDate.Text = model.ModifiedDate.ToString();
                this.txtFaPiaoXinXi.Text = model.FaPiaoXinXi;
                this.txtGoodsOrderNumber.Text = model.GoodsOrderNumber.ToString();
                this.txtBuyerComments.Text = model.BuyerComments;
                this.txtKuaiDiGongSi.Text = model.KuaiDiGongSi;
                this.txtKuaiDiDanHao.Text = model.KuaiDiDanHao;
                this.txtPeiSongXinXi.Text = model.PeiSongXinXi;
            }
        }

        public void btnSave_Click(object sender, EventArgs e)
        {
            Things.BLL.GoodsOrders bll = new Things.BLL.GoodsOrders();
            Things.Model.GoodsOrders model = bll.GetModel(GoodsOrdersID);
            if (model != null)
            {

                string strErr = "";
                if (this.txtBuyerAccount.Text.Trim().Length == 0)
                {
                    strErr += "用户帐号不能为空！\\n";
                }
                if (this.txtBuyerAddress.Text.Trim().Length == 0)
                {
                    strErr += "收货地址不能为空！\\n";
                }
                if (!PageValidate.IsDecimal(txtTotalPrice.Text))
                {
                    strErr += "订单金额格式错误！\\n";
                }
                if (!PageValidate.IsDateTime(txtBuyDate.Text))
                {
                    strErr += "购买日期格式错误！\\n";
                }
                if (!PageValidate.IsDateTime(txtSendDate.Text))
                {
                    strErr += "SendDate格式错误！\\n";
                }
                if (!PageValidate.IsDateTime(txtCancelDate.Text))
                {
                    strErr += "CancelDate格式错误！\\n";
                }
                if (this.txtStatus.Text.Trim().Length == 0)
                {
                    strErr += "Status不能为空！\\n";
                }
                if (!PageValidate.IsDateTime(txtModifiedDate.Text))
                {
                    strErr += "最新变更时间格式错误！\\n";
                }
                if (this.txtFaPiaoXinXi.Text.Trim().Length == 0)
                {
                    strErr += "发票信息不能为空！\\n";
                }
                if (!PageValidate.IsNumber(txtGoodsOrderNumber.Text))
                {
                    strErr += "GoodsOrderNumber格式错误！\\n";
                }
                if (this.txtBuyerComments.Text.Trim().Length == 0)
                {
                    strErr += "买家留言不能为空！\\n";
                }
                if (this.txtKuaiDiDanHao.Text.Trim().Length == 0)
                {
                    strErr += "快递单号不能为空！\\n";
                }
                if (this.txtPeiSongXinXi.Text.Trim().Length == 0)
                {
                    strErr += "配送信息不能为空！\\n";
                }

                if (strErr != "")
                {
                    MessageBox.Show(this, strErr);
                    return;
                }
                string BuyerAccount = this.txtBuyerAccount.Text;
                string BuyerAddress = this.txtBuyerAddress.Text;
                decimal TotalPrice = decimal.Parse(this.txtTotalPrice.Text);
                DateTime BuyDate = DateTime.Parse(this.txtBuyDate.Text);
                DateTime SendDate = DateTime.Parse(this.txtSendDate.Text);
                DateTime CancelDate = DateTime.Parse(this.txtCancelDate.Text);
                string Status = this.txtStatus.Text;
                bool IsCompleted = this.chkIsCompleted.Checked;
                DateTime ModifiedDate = DateTime.Parse(this.txtModifiedDate.Text);
                string FaPiaoXinXi = this.txtFaPiaoXinXi.Text;
                int GoodsOrderNumber = int.Parse(this.txtGoodsOrderNumber.Text);
                string BuyerComments = this.txtBuyerComments.Text;
                string KuaiDiGongSi = this.txtKuaiDiGongSi.Text;
                string KuaiDiDanHao = this.txtKuaiDiDanHao.Text;
                string PeiSongXinXi = this.txtPeiSongXinXi.Text;

                model.BuyerAccount = BuyerAccount;
                model.BuyerAddress = BuyerAddress;
                model.TotalPrice = TotalPrice;
                model.BuyDate = BuyDate;
                model.SendDate = SendDate;
                model.CancelDate = CancelDate;
                model.Status = Status;
                model.IsCompleted = IsCompleted;
                model.ModifiedDate = ModifiedDate;
                model.FaPiaoXinXi = FaPiaoXinXi;
                model.GoodsOrderNumber = GoodsOrderNumber;
                model.BuyerComments = BuyerComments;
                model.KuaiDiGongSi = KuaiDiGongSi;
                model.KuaiDiDanHao = KuaiDiDanHao;
                model.PeiSongXinXi = PeiSongXinXi;

                bll.Update(model);
                Common.MessageBox.ShowAndRedirect(this, "保存成功！", "list.aspx");
            }
        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
